
*** CZ in the liasses fiscales
cap erase "${data}/Utils/SirenZE_liasses.dta"
tempfile firm_ze
forvalues y = 4/16 {
local ystr "`y'"
if `y' < 10 {
	local ystr = "0" + "`y'"
	}
	use using "${tmp}\bicrn_`ystr'_nafcom.dta", clear
	ren *, lower
	drop naf*
	gen depcom = substr(codpost,1,2) + com
	replace depcom = "75056" if substr(depcom,1,2) == "75"
	replace depcom = "13055" if inrange(real(depcom),13201,13216)
	replace depcom = "69123" if inrange(real(depcom),69381,69389)
	replace depcom = "59183" if depcom == "59540" | depcom == "59248"
	destring depcom, replace
	merge m:1 depcom using "${data}/Utils/depcom_ZE_mapping", nogen keep(1 3)
	keep siren ZE2010
	destring siren, replace force
	drop if mi(siren) | siren == 0
	cap append using "${data}/Utils/SirenZE_liasses.dta"
	gduplicates drop siren, force
	save "${data}/Utils/SirenZE_liasses.dta", replace
	}


forvalues y = 17/20 {
	use using "${tmp}\bicrn_`y'_nafcom", clear
	ren *, lower
	drop naf*
	gen depcom = cddept + cdcommune
	replace depcom = "75056" if substr(depcom,1,2) == "75"
	replace depcom = "13055" if inrange(real(depcom),13201,13216)
	replace depcom = "69123" if inrange(real(depcom),69381,69389)
	replace depcom = "59183" if depcom == "59540" | depcom == "59248"
	destring depcom, replace force
	drop if mi(depcom)
	merge m:1 depcom using "${data}/Utils/depcom_ZE_mapping", nogen keep(1 3)
	keep siren ZE2010
	destring siren, replace force
	drop if mi(siren) | siren == 0
	cap append using "${data}/Utils/SirenZE_liasses.dta"
	gduplicates drop siren, force
	save "${data}/Utils/SirenZE_liasses.dta", replace
	}

